package example.thread;

/**
 * Created by lenovo on 2016/11/7 0007.
 * setPriority() 方法来设置线程的优先级
 * public static final int MAX_PRIORITY 10
 * public static final int MIN_PRIORITY 1
 * public static final int NORM_PRIORITY 5
 * 默认main方法也就是主线程的级别是5
 */
public class ThreadPriority extends Thread {
    private int countDown = 5;
    private volatile double d = 0;

    private ThreadPriority(int priority) {
        setPriority(priority);
        start();
    }

    public String toString() {
        return super.toString() + ": " + countDown;
    }

    public void run() {
        while (true) {
            for (int i = 1; i < 100000; i++)
                d = d + (Math.PI + Math.E) / (double) i;
            System.out.println(this);
            if (--countDown == 0) return;
        }
    }

    public static void main(String[] args) {
        new ThreadPriority(Thread.MAX_PRIORITY);
        for (int i = 0; i < 5; i++)
            new ThreadPriority(Thread.MIN_PRIORITY);
    }
}
